const router = require('express').Router();
const cityService = require('../../service/city');

/**
 * @apiDefine City  城市信息
 */

/**
 * @api {get} /v1/city/list  获取所有的城市信息
 * @apiVersion 1.0.0
 * @apiName GetCityList
 * @apiGroup  City
 *
 * @apiDescription 获取所有的城市信息
 *
 * @apiExample Example usage:
 * curl -i http://localhost:3502/v1/city/list
 *
 * @apiSuccess {Number} code      请求结果编码，0：正常， 其他为异常
 * @apiSuccess {string} message    请求结果编码对应的message
 * @apiSuccess {Object[]} data    返回值数据
 * @apiSuccess {String} data.sign  签名
 * @apiSuccess {String} data.host  域名
 * @apiSuccess {String} data.accessKeyId  accessKeyId
 *
 * @apiSuccessExample 正常响应：
 *     HTTP/1.1 200
 {
        "code": 200,
        "message": "请求成功",
        "data": {
            "sign": "5ushpBPjC97G9/2HunrMH2CRhj0=",
            "host": "xiaoqingjing.oss-cn-beijing.aliyuncs.com",
            "accessKeyId": "LTAI08SBNqF6OJqX"
        }
    }
 *
 *
 * @apiError  ServerError  服务器异常
 *
 * @apiErrorExample Response (example):
 *     HTTP/1.1 500 ServerError
 *     {
 *       "code": 500,
 *       "message": "服务器异常"
 *     }
 */
router.get('/list', (req, res, next) => {
  cityService.getList()
    .then((data) => res.success(data))
    .catch(e => next(e))
});

module.exports = router;
